package com.qyl.honghengshop.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;






import java.util.Map;

import com.qyl.honghengshop.dao.GoodsDao;
import com.qyl.honghengshop.dao.GoodsTypeDao;
import com.qyl.honghengshop.dao.impl.GoodsDaoImpl;
import com.qyl.honghengshop.dao.impl.GoodsTypeDaoImpl;
import com.qyl.honghengshop.dto.Goods;
import com.qyl.honghengshop.dto.IndexGoods;
import com.qyl.honghengshop.service.GoodsService;
import com.qyl.honghengshop.utils.PageBean;

public class GoodsServiceImpl implements GoodsService {

	private GoodsDao goodsDao = new GoodsDaoImpl();
	private GoodsTypeDao goodsTypeDao = new GoodsTypeDaoImpl();
	
	@Override
	public int getRecordCount(Goods goods) {

		return goodsDao.getRecordCount(goods);
	}

	@Override
	public void shopTypeList(PageBean pageBean, Goods goods) {

		goodsDao.shopTypeList(pageBean,goods);
		
	}

	@Override
	public int saveShop(Goods goods) {

		return goodsDao.saveShop(goods);
	}

	@Override
	public int delShop(Integer id) {

		
		return goodsDao.delShop(id);
	}

	@Override
	public Goods getShopById(Integer id) {

		return goodsDao.getShopById(id);
	}

	@Override
	public int updateShop(Goods goods) {

		
		return goodsDao.updateShop(goods);
	}

	@Override
	public List<Goods> getAllShop() {

		return goodsDao.getAllShop();

	}

	@Override
	public List<Goods> getGoodsListIsHot() {

		return goodsDao.getGoodsListIsHot();
	}

	@Override
	public List<IndexGoods> getIndexGoodsList() {

		int goodsTypeNum = goodsTypeDao.getIndexTypeNum();
		
		List<IndexGoods> indexGoodsList = new ArrayList<IndexGoods>();
		
		for (int i = 0; i <goodsTypeNum; i++) {
			
			IndexGoods indexGoods = new IndexGoods();
			
			//获得首页展示栏位未i+1的商品类型code
			Map<String, String> map = goodsTypeDao.getCodeByIndexFiled(i+1);
			
			List<Goods> list = goodsDao.getGoodsByCode(map.get("code"));
			
			indexGoods.setIndex_field(i+1);
			
			indexGoods.setList(list);
			
			indexGoods.setGoodsType(map.get("name"));
			
			indexGoodsList.add(indexGoods);		
		}		
		return indexGoodsList;
	}


}
